/*

    SHASHANK BHYRAVAVAJJULA ... 28/1/14
    BILLING ENTRY FORM

*/

//Combinations GH and BO arent working !!!! Ask Sir about this ....

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<ctype.h>

void main()
{
  int ino=0,qty=0,k=0,l;
  char iname[50],bool,uname[50];
  float price=0.0,subtotal=0.0,grandtotal=0.0;

  clrscr();


  textbackground(CYAN);
  gotoxy(1,1);
  for(int i=0;i<=250;i++)
   for(int j=0;j<=80;j++)
    cprintf(" ");

  //Header

  gotoxy(1,1);
  for(i=0;i<=26;i++)
  {
    printf("%c",15);
  }

  textcolor(WHITE);
  cprintf("SHASHANK ENTERPRISES");
  for(i=45;i<=77;i++)  //Change the value of 77 according to the system
   printf("%c",15);
  //Header Closed


  //Line above the subheadings
  gotoxy(1,2);
  for(i=0;i<=78;i++) // Change the value of 77 acc to system
    printf("%c",95);
  //Line below the subheadings


    gotoxy(1,3);
    textbackground(CYAN);
    textcolor(BLACK);
    cprintf("Item No.");
    //gotoxy(8,4);
    for(i=3;i<25;i++) //Change value of 25 acc to req (Horizontal Line)
     {
       gotoxy(9,i);
       printf("%c",179);
     }

    gotoxy(10,3);
    cprintf("       I t e m  N a m e        ");
    for(i=3;i<25;i++) //Change the value of 25 acc to req
     {
       gotoxy(43,i);
       printf("%c",179);
     }

    gotoxy(44,3);
    cprintf(" Price(Rs.) ");
    for(i=3;i<25;i++) //Change the value of 25 acc to req
     {
       gotoxy(56,i);
       printf("%c",179);
     }

     gotoxy(57,3);
     cprintf(" Qty ");
     for(i=3;i<25;i++) // Change value of 25 acc ro req
     {
       gotoxy(62,i);
       printf("%c",179);
     }

     gotoxy(63,3);
     cprintf("   Sub Total  ");
     for(i=3;i<25;i++) // Change value of 25 acc to req
     {
       gotoxy(77,i);
       printf("%c",179);
     }


     //Line below the sub headings .. Edit acc to the system

     gotoxy(1,4);
     for(i=0;i<8;i++) //Change value of 8 acc to req
      printf("%c",95);

     gotoxy(i=i+2,4);
     for(;i<43;i++)
      printf("%c",95);

     gotoxy(++i,4);
     for(;i<56;i++)
      printf("%c",95);

     gotoxy(++i,4);
     for(;i<62;i++)
      printf("%c",95);

     gotoxy(++i,4);
     for(;i<80;i++)
      printf("%c",95);

     //Line after subheading closed
     j=6;
     textcolor(BLACK);

     do
     {
       //Item Number
       i=8;
       k=i;
       textbackground(CYAN);
       gotoxy(1,j);
       cprintf("%4d",(++ino));
       //Item Number Closed

       textbackground(WHITE);

       //item name

       gotoxy(i=i+2,j);
       k=i;
       for(;i<43;i++)
	cprintf(" ");

       fflush(stdin);
       gotoxy(k,j);
       gets(iname);

       textbackground(CYAN);
       gotoxy(k,j);
       for(;k<43;k++)
	cprintf(" ");

       for(l=0;l<=50;l++)
       {
	 if(l==0)
	  uname[l]=toupper(iname[l]);
	 else
	  uname[l]=iname[l];
       }
	//uname = strupr(iname);    //whole string to uppercase using ptrs ;uname should be a char pointer

       gotoxy(11,j);
       cprintf("%s",uname);

       //Item Name Closed

       //Item Price

       textbackground(WHITE);
       gotoxy(++i,j);
       k=i;
       for(;i<56;i++)
	cprintf(" ");

       gotoxy(k,j);
       scanf("%f",&price);


       textbackground(CYAN);
       gotoxy(k,j);
       for(;k<56;k++)
	cprintf(" ");

       gotoxy(45,j);
	cprintf("%10.2f",price);

       //Item Price Closed


       //Item Quantity Open

       textbackground(WHITE);
       gotoxy(++i,j);
       k=i;
       for(;i<62;i++)
	cprintf(" ");

       gotoxy(k,j);
       scanf("%d",&qty);


       textbackground(CYAN);
       gotoxy(k,j);
       for(;k<62;k++)
	cprintf(" ");

       gotoxy(58,j);
	cprintf("%3d",qty);


       //Item Quantity Closed

       //Subtotal Open
       subtotal=price*qty;
       gotoxy(++i,j);
       cprintf("%12.02f",subtotal);
       //l=i;
       grandtotal=subtotal+grandtotal;

       textbackground(CYAN);

       gotoxy(30,23);
       printf("Do u want to continue(y/n)?");
       _setcursortype(_SOLIDCURSOR);
       bool=getche();
       if(bool=='y'||bool=='Y')
	{
	 gotoxy(58,23);
	 printf("\b ");
	}
	j++;

       _setcursortype(_NORMALCURSOR);

     }while(bool=='y');

     textbackground(CYAN);
     textcolor(BLACK);
     gotoxy(1,(j+2));
     for(i=0;i<79;i++)
      printf("%c",95);
     gotoxy(20,(j+2));
      cprintf("THE GRAND TOTAL IS :");

     textcolor(BLUE+BLINK);
     cprintf("%.2f",grandtotal);

     textbackground(CYAN);
     gotoxy(30,23);

     for(i=0;i<31;i++);
     cprintf(" ");

     textcolor(RED);
     gotoxy(10,23);
     cprintf("Billing Done .. Thank You for shopping at SHASHANK ENTERPRISES ");

     _setcursortype(_NOCURSOR);
      //printf("test co rodinates " );



 getch();
}

